// pages/user/feedBack/feedBack.js
var app = getApp();
var submitOne = false;//避免重复提交
Page({
  /**
   * 页面的初始数据
   */
  data: {
    labels:[],
    labelIndex: 1,
    text:'',
    email:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getOpinionType();  // 意见标签表
  },
  onShow: function(){
    submitOne = false;
  },

  // 获取意见标签表
  getOpinionType () {
    var that = this;
    app.ajax({
      url: 'User/Opinion/getOpinionType',
      data: {},
      success: function (res) {
        if (res.data.code == 1000) {
          // 数据赋值
          that.setData({
            labels: res.data.data,
            labelIndex: res.data.data[0].opinion_type_id
          })
        }
        
      }
    })
  },

  // 提交意见
  Submit: function () {
    var that = this;
    var content = that.data.text; // 意见内容
    var email = that.data.email;  // 邮箱
    var opinion_type_id = that.data.labelIndex; // 标签ID
    if (this.data.text == '' || this.data.text == null) {
      app.showToast('意见不能为空')
      return;
    }
    console.log('submitOne' + submitOne);
    if (submitOne){
      return;
    }
    submitOne = true;
    // ajax请求
    app.ajax({
      url: 'User/Opinion/addOpinionFeedback',
      data: { opinion_type_id: opinion_type_id, content: content, email: email },
      success: function (res) {
        submitOne = false;
        if (res.data.code == 1000) {
          app.showToast(res.data.message);
          setTimeout(()=>{
            wx.navigateBack({
              delta: 1
            })
          },1000)
        }else{
          app.showToast('您的输入可能不合法或是敏感词汇哟，请检查~');
        }
      }
    })
  },

 
  /**
   * 点击标签
   */
  bindLabel: function (e) {
    console.log(e.currentTarget.dataset.labelid);
    this.setData({
      labelIndex: e.currentTarget.dataset.labelid
    })
    console.log(this.data.labelIndex);
  },
   /**
    * 绑定textarea
   */
  feedBacktext:function(e){
    console.log(e.detail.value);
    this.setData({
      text: e.detail.value
    })
  },
  /**
    * 绑定email
   */
  feedBackemail: function (e) {
    console.log(e.detail.value);
    this.setData({
      email: e.detail.value
    })

  },

})